#include <stdio.h>
#include <stdlib.h>
#include <sys/statvfs.h>

int main() {
    struct statvfs vfs_info;
    unsigned long long total_space, free_space;
    double percent_free;

    // 获取文件系统信息
    // 第一个参数为文件挂载位置（非文件系统）
    if (statvfs("/", &vfs_info) == -1) {
        perror("statvfs");
        exit(EXIT_FAILURE);
    }

    // 获取总空间和可用空间
    total_space = (unsigned long long)vfs_info.f_blocks * vfs_info.f_frsize;
    free_space = (unsigned long long)vfs_info.f_bfree * vfs_info.f_frsize;

    // 计算剩余空间百分比
    percent_free = ((double)free_space / total_space) * 100.0;

    printf("剩余ROM百分比：%.2f%%\n", percent_free);

    return 0;
}